package icasue.tools.sqlhelper.core;

import lombok.SneakyThrows;
import icasue.reflect.annotations.NotNull;
import icasue.reflect.annotations.Nullable;

import java.sql.SQLException;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/10/14 下午4:28
 * @UpdateDate:
 * @Description:
 */
class Limit {
    @Nullable
    public Integer offset;
    @NotNull
    public Integer size;

    @SneakyThrows(Throwable.class)
    Limit(Integer page,Integer size){
        if(size == null || size <= 0){
            throw new SQLException("query limit 'size' required bigger than 0 rows.");
        }else {
            this.size = size;
        }

        if(page == null){
            this.offset = 0;
        }else if(page <= 0){
            throw new SQLException("query 'page' required bigger than 0 rows.");
        }else {
            this.offset = (page - 1) * size;
        }
    }
}
